
def read_config(config_file):
    """
    从配置文件中读取数据库连接属性
    :param config_file: 配置文件路径，默认为db_config.txt
    :return: 包含配置参数的字典
    """
    config = {}

    try:
        with open(config_file, 'r', encoding='utf-8') as f:
            for line in f:
                line = line.strip()
                # 跳过空行和注释行（以#开头的行）
                if not line or line.startswith('#'):
                    continue

                # 使用=分割键值对
                if '=' in line:
                    key, value = line.split('=', 1)
                    config[key.strip()] = value.strip()

    except FileNotFoundError:
        print(f"错误：配置文件 {config_file} 未找到")
    except Exception as e:
        print(f"读取配置文件时出错: {e}")

    return config
